{include file="public/header" /}
<style>
    .layui-form-switch {
        height: 24px;
        line-height: 24px;
        width: 55px;
        margin-top: 0;
    }
</style>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>店铺设置</h5>
        </div>
        <div class="ibox-content" style="padding: 0 15px;">
            <div class="example-wrap">
                <div class="example" id="settings">
                    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                        <ul class="layui-tab-title">
                            <li class="layui-this">商城设置</li>
                            <li>购物/提现流程</li>
                            <li>物流设置</li>
                        </ul>
                        <div class="layui-tab-content" style="padding: 10px 0;">
                            <!--商城设置-->
                            <div class="layui-tab-item layui-show">
                                <div class="layui-row">
                                    <form action="" class="layui-form layui-form-pane">
                                        <div class="layui-col-xs12">
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">店铺名称</label>
                                                <div class="layui-input-block">
                                                    <input type="text" name="shop_name" class="layui-input"
                                                           lay-verify="required" lay-verType="tips"
                                                           value="{$shop['shop_name']}"
                                                           placeholder="请输入店铺名称"/>
                                                    <div class="layui-form-mid layui-word-aux">在订单他商品中显示</div>
                                                </div>
                                            </div>
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">店铺LOGO</label>
                                                <div class="layui-input-block">
                                                    <div class="layui-col-xs12" style="margin-bottom: 10px;">
                                                        <input type="hidden" name="shop_logo" id="shop_logo"
                                                               value="{$shop['shop_logo']}">
                                                        <input type="file" id="file" class="layui-input" title="选择图片"/>
                                                    </div>
                                                    <div class="layui-clear">
                                                        <div class="layui-col-xs5">
                                                            <div id="clipArea"></div>
                                                        </div>
                                                        <div class="layui-col-xs2">
                                                            <div id="clipBtn_div">
                                                                <button id="clipBtn" type="button" class="layui-btn">剪裁
                                                                </button>
                                                            </div>
                                                        </div>
                                                        <div class="layui-col-xs5">
                                                            <div id="view"
                                                                 style="background: url(/static/uploads/shop_logo/{$shop['shop_logo']})"></div>
                                                        </div>
                                                    </div>
                                                    <div class="layui-form-mid layui-word-aux">在订单中显示</div>
                                                </div>
                                            </div>
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">联系电话</label>
                                                <div class="layui-input-block">
                                                    <input type="text" name="shop_phone" class="layui-input"
                                                           lay-verify="required" lay-verType="tips"
                                                           value="{$shop['shop_phone']}"
                                                           placeholder="请输入电话号码">
                                                    <div class="layui-form-mid layui-word-aux">在订单和商品中显示，方便客户遇到问题时咨询
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">具体地址</label>
                                                <div class="layui-input-block">
                                                    <input type="text" name="shop_address" class="layui-input"
                                                           value="{$shop['shop_address']}"
                                                           lay-verify="required" lay-verType="tips" placeholder="请输入地址">
                                                    <div class="layui-form-mid layui-word-aux">具体地址</div>
                                                </div>
                                            </div>
                                            <div class="layui-form-item">
                                                <div class="layui-input-block">
                                                    <input type="hidden" name="type" value="shop">
                                                    <a class="layui-btn" lay-submit lay-filter="shop">提交</a>
                                                    <a href="javascript:history.back(-1)"
                                                       class="layui-btn layui-btn-danger">返回</a>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                            <!--购物/提现流程-->
                            <div class="layui-tab-item">
                                <form action="" class="layui-form layui-form-pane">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">自动收货</label>
                                        <div class="layui-input-block">
                                            <select name="shouhuo_day">
                                                {for start="1" end="31" step="1" name="day"}
                                                <option value="{$day}" {if condition="$tixian['shouhuo_day'] eq $day"}selected{/if}>{$day}天</option>
                                                {/for}
                                            </select>
                                            <div class="layui-form-mid layui-word-aux">发货后多少天自动收货</div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">申请售后</label>
                                        <div class="layui-input-block">
                                            <select name="shouhou_day">
                                                {for start="1" end="31" step="1" name="day"}
                                                <option value="{$day}" {if condition="$tixian['shouhou_day'] eq $day"}selected{/if}>{$day}天</option>
                                                {/for}
                                            </select>
                                            <div class="layui-form-mid layui-word-aux">申请售后的时间段（交易完成多少天内），换货或维修</div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">提现金额</label>
                                        <div class="layui-input-block">
                                            <input type="number" name="tixian_jine" class="layui-input"
                                                   lay-verify="required|number" lay-verType="tips"
                                                   value="{$tixian['tixian_jine']}"
                                                   placeholder="请输入提现金额"/>
                                            <div class="layui-form-mid layui-word-aux">需超过多少才能提现金额</div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">提现额度</label>
                                        <div class="layui-input-block">
                                            <input type="number" name="tixian_edu" class="layui-input"
                                                   lay-verify="required|number" lay-verType="tips"
                                                   value="{$tixian['tixian_edu']}"
                                                   placeholder="请输入提现额度"/>
                                            <div class="layui-form-mid layui-word-aux">最少提现多少，才能提现</div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <input type="hidden" name="type" value="shopTiXian">
                                            <a class="layui-btn" lay-submit lay-filter="shop_tixian">提交</a>
                                            <a href="javascript:history.back(-1)"
                                               class="layui-btn layui-btn-danger">返回</a>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <!--物流设置-->
                            <div class="layui-tab-item">
                                <form class="layui-form">
                                    <table class="layui-table">
                                        <colgroup>
                                            <col width="60">
                                            <col width="200">
                                            <col width="70">
                                            <col>
                                            <col width="90">
                                        </colgroup>
                                        <thead>
                                        <tr>
                                            <th>序号</th>
                                            <th>物流名称</th>
                                            <th>LOGO</th>
                                            <th>物流代码</th>
                                            <th>是否启用</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        {foreach name="code" id="value" key="index"}
                                        <tr>
                                            <td align="center">{$index+1}</td>
                                            <td>
                                                {$value['name']}
                                                <input type="hidden" name="{$index}[name]" value="{$value['name']}">
                                            </td>
                                            <td align="center">
                                                <img src="/static/logo/{$value['type']}.jpg" alt=""
                                                     style="height: 30px;">
                                            </td>
                                            <td>
                                                {$value['type']}
                                                <input type="hidden" name="{$index}[type]" value="{$value['type']}">
                                            </td>
                                            <td align="center">
                                                <input type="hidden" name="{$index}[status]" id="status_{$index}"
                                                       value="{$value['status']}">
                                                <input type="checkbox" data-name="status_{$index}"
                                                       value="{$value['status']}" lay-skin="switch" lay-text="启用|关闭"
                                                       lay-filter="status" {$value['status']==1?'checked':''}>
                                            </td>
                                        </tr>
                                        {/foreach}
                                        </tbody>
                                    </table>
                                    <button lay-submit lay-filter="code" id="code" style="border: none;"></button>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script src="/static/load/js/jquery-2.1.3.min.js"></script>
<script src="/static/load/js/iscroll-zoom.js"></script>
<script src="/static/load/js/hammer.js"></script>
<script src="/static/load/js/jquery.photoClip.js"></script>
<script type="text/javascript">
    var form = layui.form, table = layui.table;
    /**
     * 更改物流开启状态
     */
    form.on('submit(code)', function (data) {
        var param = data.field;
        $.post("{:url('setting')}", param, function (response) {
        });
        return false;
    });
    /**
     * 监听物流开启状态点击
     */
    form.on('switch(status)', function (obj) {
        var name = $(this).data('name'), thisValue = this.value;
        var value = thisValue == '1' ? '0' : '1';
        $(this).val(value);
        $('#' + name).val(value);
        $('#code').click();
    });
    /**
     * 添加配置
     */
    form.on('submit(shop)', function (data) {
        var param = data.field;
        if (!param.shop_logo) {
            layer.tips('请上传店铺LOGO', '#file', {tips: 1});
            return false;
        }
        $.post("{:url('setting')}", param, function (response) {
            layer.msg(response.msg);
        });
        return false;
    });
    /**
     * 添加配置
     */
    form.on('submit(shopTiXian)', function (data) {
        var param = data.field;
        $.post("{:url('setting')}", param, function (response) {
            layer.msg(response.msg);
        });
        return false;
    });

    $(function () {
        /**
         * 剪裁上传LOGO
         */
        $("#clipArea").photoClip({
            width: 100,
            height: 100,
            file: "#file",
            view: "#view",
            ok: "#clipBtn",
            loadStart: function (obj) {
                // console.log("照片读取中");
            },
            loadComplete: function (obj) {
                // console.log("照片读取完成");
            },
            clipFinish: function (dataURL) {
                $.ajax({
                    url: "{:url('Upload/upload_base64')}",
                    data: {file: dataURL, path: 'shop_logo'},
                    type: 'post',
                    dataType: 'json',
                    success: function (response) {
                        // console.log(response);
                        if (response.code > 0) {
                            layer.tips(response.msg, '#file', {tips: 1});
                        } else {
                            $('#shop_logo').val(response.data);
                        }
                    }
                })
            }
        });
    })
</script>
</body>
</html>